/*
package com.gancp.common.security;

import com.gancp.Exception.BadCredentialException;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;

*/
/**
 * Created by GCP on 2018/1/21.
 *//*

public class RestAuthenticationProvider implements AuthenticationProvider {
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {

        if (authentication instanceof PreAuthenticatedAuthenticationToken) {
            PreAuthenticatedAuthenticationToken preAuth = (PreAuthenticatedAuthenticationToken) authentication;
            RestAuthenticationToken sysAuth = (RestAuthenticationToken) preAuth.getPrincipal();
            if (sysAuth.getAuthorities() != null && sysAuth.getAuthorities().size() > 0) {
                GrantedAuthority authority = sysAuth.getAuthorities().iterator().next();
                if ("BIKE_CLIENT".equals( authority.getAuthority() )) {
                    return sysAuth;

                } else if ("ROLE_SOMEONE".equals( authority.getAuthority() )) {
                    return sysAuth;
                }
            }
        } else if (authentication instanceof RestAuthenticationToken) {
            RestAuthenticationToken sysAuth = (RestAuthenticationToken) authentication;
            if (sysAuth.getAuthorities() != null && sysAuth.getAuthorities().size() > 0) {
                GrantedAuthority gauth = sysAuth.getAuthorities().iterator().next();
                if ("BIKE_CLIENT".equals( gauth.getAuthority() )) {
                    return sysAuth;
                } else if ("BIKE_CLIENT".equals( gauth.getAuthority() )) {
                    return sysAuth;
                }
            }
        }
        // 授权异常
        throw new BadCredentialException( "unknow.error" );
    }

    @Override
    public boolean supports(Class<?> authentication) {

        return PreAuthenticatedAuthenticationToken.class.isAssignableFrom( authentication ) || RestAuthenticationToken.class.isAssignableFrom( authentication );


    }
}
*/
